package leecode

func findTarget(root *TreeNode, k int) bool {
	hashMap := make(map[int]int) //key为节点值, value为出现的次数
	//中序遍历
	var traversal func(node *TreeNode)
	traversal = func(node *TreeNode) {
		if node == nil {
			return
		}
		hashMap[node.Val]++
		traversal(node.Left)
		traversal(node.Right)
	}
	traversal(root)
	for key, _ := range hashMap {
		hashMap[key]--
		if hashMap[k-key] > 0 {
			return true
		}
	}
	return false
}
